package hu.elte.inf.holiuml.model;

import java.awt.Graphics;
import java.util.StringTokenizer;

import hu.elte.inf.holiuml.model.Node;

/**
 * @author Csaba Hoch
 */
public class CommentNode extends Node {

	/**
	 * The size of the dog ear in pixels.
	 */
	static final int dogEarSize = 10;

	/**
	 * The text of the comment. It may contain newline characters.
	 */
	String text = "";

	@Override
	protected void recalculateLines(Graphics g) {
		StringTokenizer st = new StringTokenizer(text, "\r\n");
		while (st.hasMoreTokens()) {
			lines.add(st.nextToken());
		}
	}
	
	@Override
	protected void recalculateSize(Graphics g) {
		super.recalculateSize(g);
		width += dogEarSize;
	}

	@Override
	protected void drawBounds(Graphics g) {
		// Drawing the bounds.s
		g.setColor(java.awt.Color.BLACK);
		g.drawRect(getX(), getY(), getWidth(), getHeight());

		// Drawing the dog ears.
		g.drawRect(getX() + getWidth() - dogEarSize, getY(), dogEarSize,
				dogEarSize);
		g.setColor(java.awt.Color.WHITE);
		g.drawLine(getX() + getWidth() - dogEarSize + 1, getY(), getX()
				+ getWidth(), getY());
		g.drawLine(getX() + getWidth(), getY(), getX() + getWidth(), getY()
				+ dogEarSize - 1);
		g.setColor(java.awt.Color.BLACK);
		g.drawLine(getX() + getWidth() - dogEarSize + 1, getY(), getX()
				+ getWidth(), getY() + dogEarSize - 1);
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
		sizeUpToDate = false;
	}
}
